﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Expectation_Maximization
{
	class Program
	{
		static void Main(string[] args)
		{

			if (args.Length == 0)
			{
				Console.WriteLine("Please specify an input file containing fasta formatted sequences");
				Console.Read();
				Environment.Exit(0);
			}
			
			//Ok so
			//Read in a bunch of sequences
			//After that pick a random subsequence of length 6 from each sequences
			//Do the following analyitics on the subsequences for each nucleotide
			//	Count the number of times it appears at each position and how many times it appears outside of the subsequence (motif)
			//	Convert that into a frequency table 
			//	From the frequency table take the log base 2 of the frequency of each nucleotide at that position divided by the frequency of it not being in the motif at all
			//	log base 2 of observed divided by expected
			//	Ready, break!

			#region Get options from user
			int motifSize, iterations, numInitialAlignments;
			Console.Write("How big should the motif be? (Default 6) ");
			Nullable<int> tmp = HelperFunctions.GetNumericInput();
			if (tmp == null)
				motifSize = 6;
			else
				motifSize = tmp.Value;
			Console.WriteLine();

			Console.Write("How many iterations should be run? (Default 500) ");
			tmp = HelperFunctions.GetNumericInput();
			if (tmp == null)
				iterations = 50;
			else
				iterations = tmp.Value;
			Console.WriteLine();
			
			Console.Write("How many starting alignments should be used? (Default 50)");
			tmp = HelperFunctions.GetNumericInput();
			if (tmp == null)
				numInitialAlignments = 50;
			else
				numInitialAlignments = tmp.Value;
			Console.WriteLine();
			#endregion			

			List<HelperFunctions.Sequence> junk = HelperFunctions.ImportSequence(args[0]);
			ExpectationMaximizer em = new ExpectationMaximizer(junk, motifSize);
			em.EM(numInitialAlignments, iterations);
			Console.ReadLine();

		}
	}
}
